<!DOCTYPE html>
<html lang="zh">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    input{
      width: 100px;
    }
  </style>
</head>

<body>
  <h3>请输入两个数字，得到两数之间[n,m)的一个任意排序数组</h3>
  <input type="text" placeholder="请输入任意数字">
  <input type="text" placeholder="请输入任意数字">
  <button id="btn">排序数组</button>
  <p></p>
  <p></p>
</body>

</html>
<script>
  var inputObjs = document.getElementsByTagName('input');
  var buttonObj = document.getElementById('btn');
  var pObjs = document.getElementsByTagName('p');

  for (var i = 0; i < inputObjs.length; i++) {
    inputObjs[i].oninput = function () {
      var reg = /\D/g;
      this.value = this.value.replace(reg, '') // 除了0-9都替换空值
    };
    inputObjs[i].onpaste = function () {
      return false;
    }
  }
  buttonObj.onclick = function () {
    if (inputObjs[0].value == '') {
      console.log('请输入第一个数');
    } else if (inputObjs[1].value == '') {
      console.log('请输入第二个数');
    } else {
      var arr = [];
      var n = Number(inputObjs[0].value);
      var m = Number(inputObjs[1].value);
      function randomNum(n, m) {
        var num = parseInt(Math.abs(Math.random() * (m - n) + n));
        return num;
      }
      for (var i = 0; i < 10; i++) {
        arr.push(randomNum(n, m));
      }
      function sequentialArray(arr) {
        var temp = arr.sort(function (a, b) {
          return a - b;
        });
        return temp;
      }
      console.log('生成数组',arr);
      pObjs[0].innerText = "生成数组：" + arr;
      console.log('排序数组',sequentialArray(arr));
      pObjs[1].innerText = "排序数组：" + sequentialArray(arr);
    }
  }
</script>